#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
import os

from gen_py.HelloService import HelloService
from gen_py.HelloService.ttypes import *
from gen_py.HelloService.constants import *
import json
json_loads = json.loads
json_dumps = json.dumps


from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

def testQuery(jsonCondition):
    try:
        # Make socket
        transport = TSocket.TSocket('192.168.1.10', 30303)
    
        # Buffering is critical. Raw sockets are very slow
        transport = TTransport.TBufferedTransport(transport)
    
        # Wrap in a protocol
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
    
        # Create a client to use the protocol encoder
        client = HelloService.Client(protocol)
    
        # Connect!
        transport.open()
       
        res2 = client.say_hello(jsonCondition)
        print(res2)
        transport.close()
    
    except Thrift.TException as tx:
        print( "%s" % (tx.message))

if __name__ == '__main__':
    condition =  {"路线编号": "G5513_0",
                 #"名称": "项目",
                 #"起点位置": "123",
                 #"终点位置": "456",
                 #"起点桩号": 123,
                 #"终点桩号": 123,
                 #"路线长度": 123,
                 }
    condition = [("路线编号", "G5513_1%", "LIKE")]
    jsonCondition = json_dumps(condition)
    for i in range(10000):
        testQuery(jsonCondition)